package com.yike.user.controller;

import com.yike.user.entity.CategoryCount;
import com.yike.user.service.CategoryCountService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.CategoryCountPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 商品分类统计 控制器
 *
 * @author Sakura
 * @since 2024-11-19
 */
@Slf4j
@RestController
@RequestMapping("/categoryCount")
@Module("user")
@Api(value = "商品分类统计API", tags = {"商品分类统计"})
@ApiIgnore
public class CategoryCountController extends BaseController {

    @Autowired
    private CategoryCountService categoryCountService;

    /**
     * 添加商品分类统计
     */
    @PostMapping("/add")
    @OperationLog(name = "添加商品分类统计", type = OperationLogType.ADD)
    @ApiOperation(value = "添加商品分类统计", response = ApiResult.class)
    public ApiResult<Boolean> addCategoryCount(@Validated(Add.class) @RequestBody CategoryCount categoryCount) throws Exception {
        boolean flag = categoryCountService.saveCategoryCount(categoryCount);
        return ApiResult.result(flag);
    }

    /**
     * 修改商品分类统计
     */
    @PostMapping("/update")
    @OperationLog(name = "修改商品分类统计", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改商品分类统计", response = ApiResult.class)
    public ApiResult<Boolean> updateCategoryCount(@Validated(Update.class) @RequestBody CategoryCount categoryCount) throws Exception {
        boolean flag = categoryCountService.updateCategoryCount(categoryCount);
        return ApiResult.result(flag);
    }

    /**
     * 删除商品分类统计
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除商品分类统计", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除商品分类统计", response = ApiResult.class)
    public ApiResult<Boolean> deleteCategoryCount(@PathVariable("id") Long id) throws Exception {
        boolean flag = categoryCountService.deleteCategoryCount(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取商品分类统计详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "商品分类统计详情", type = OperationLogType.INFO)
    @ApiOperation(value = "商品分类统计详情", response = CategoryCount.class)
    public ApiResult<CategoryCount> getCategoryCount(@PathVariable("id") Long id) throws Exception {
        CategoryCount categoryCount = categoryCountService.getById(id);
        return ApiResult.ok(categoryCount);
    }

    /**
     * 商品分类统计分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "商品分类统计分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商品分类统计分页列表", response = CategoryCount.class)
    public ApiResult<Paging<CategoryCount>> getCategoryCountPageList(@Validated @RequestBody CategoryCountPageParam categoryCountPageParam) throws Exception {
        Paging<CategoryCount> paging = categoryCountService.getCategoryCountPageList(categoryCountPageParam);
        return ApiResult.ok(paging);
    }

}

